package com.gitee.sparta.examples;

import com.gitee.sparta.core.cluster.ClusterCache;
import com.gitee.sparta.core.cluster.balance.NodeLoadBalance;
import org.apache.tomcat.util.security.MD5Encoder;

import java.nio.charset.StandardCharsets;

public class NodeBalanceExample {

    public static void main(String[] args) {
        ClusterCache.leaderIsolation = "3";
        NodeLoadBalance balance = NodeLoadBalance.getNodeLoadBalanceInstance();

        for (int i = 0; i < 5; i++) {
            balance.addNode(String.valueOf(i), i);
        }


        for (int i = 0; i < 20; i++) {
            balance.switchover(true, 2);
            String balanced = balance.balance();
            System.out.println(balanced);
        }
    }
}
